package com.cutefool.zero.code.dictionary.domain;

import com.cutefool.dsl.mybatis.core.objects.DslDomain;
import jakarta.annotation.Generated;
import java.sql.JDBCType;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.UnaryOperator;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.SqlColumn;
import org.mybatis.dynamic.sql.insert.InsertDSL;
import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateModel;

@Data
@EqualsAndHashCode(callSuper = true)
public class DicDefine extends DslDomain<DicDefine> {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private Long id;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private String name;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private String code;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private String structure;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private String valueType;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private String otherSetting;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private String description;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private Long createBy;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private Long updateBy;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private LocalDateTime createTime;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    private LocalDateTime updateTime;

    private static final DicDefine instance = new DicDefine();

    private static final Table table = new Table();

    public static DicDefine instance() {
        return instance;
    }

    @Override
    public Table table() {
        return table;
    }

    @Override
    @SuppressWarnings("DuplicatedCode")
    public UnaryOperator<InsertDSL<DicDefine>> insert() {
        return (InsertDSL<DicDefine> dsl) -> {
            dsl.map(table.id).toProperty("id");
            dsl.map(table.name).toProperty("name");
            dsl.map(table.code).toProperty("code");
            dsl.map(table.structure).toProperty("structure");
            dsl.map(table.valueType).toProperty("valueType");
            dsl.map(table.otherSetting).toProperty("otherSetting");
            dsl.map(table.description).toProperty("description");
            dsl.map(table.createBy).toProperty("createBy");
            dsl.map(table.updateBy).toProperty("updateBy");
            dsl.map(table.createTime).toProperty("createTime");
            dsl.map(table.updateTime).toProperty("updateTime");
            return dsl;
        };
    }

    @Override
    @SuppressWarnings("DuplicatedCode")
    public UnaryOperator<MultiRowInsertDSL<DicDefine>> insertMultiple() {
        return (MultiRowInsertDSL<DicDefine> dsl) -> {
            dsl.map(table.id).toProperty("id");
            dsl.map(table.name).toProperty("name");
            dsl.map(table.code).toProperty("code");
            dsl.map(table.structure).toProperty("structure");
            dsl.map(table.valueType).toProperty("valueType");
            dsl.map(table.otherSetting).toProperty("otherSetting");
            dsl.map(table.description).toProperty("description");
            dsl.map(table.createBy).toProperty("createBy");
            dsl.map(table.updateBy).toProperty("updateBy");
            dsl.map(table.createTime).toProperty("createTime");
            dsl.map(table.updateTime).toProperty("updateTime");
            return dsl;
        };
    }

    @Override
    public void updateAllColumns(UpdateDSL<UpdateModel> dsl) {
        dsl.set(table.name).equalTo(this::getName)
           .set(table.code).equalTo(this::getCode)
           .set(table.structure).equalTo(this::getStructure)
           .set(table.valueType).equalTo(this::getValueType)
           .set(table.otherSetting).equalTo(this::getOtherSetting)
           .set(table.description).equalTo(this::getDescription)
           .set(table.createBy).equalTo(this::getCreateBy)
           .set(table.updateBy).equalTo(this::getUpdateBy)
           .set(table.createTime).equalTo(this::getCreateTime)
           .set(table.updateTime).equalTo(this::getUpdateTime);
        dsl.where(table.id, SqlBuilder.isEqualTo(this::getId));
    }

    @Override
    public void updateSelectiveColumns(UpdateDSL<UpdateModel> dsl) {
        dsl.set(table.name).equalToWhenPresent(this::getName)
           .set(table.code).equalToWhenPresent(this::getCode)
           .set(table.structure).equalToWhenPresent(this::getStructure)
           .set(table.valueType).equalToWhenPresent(this::getValueType)
           .set(table.otherSetting).equalToWhenPresent(this::getOtherSetting)
           .set(table.description).equalToWhenPresent(this::getDescription)
           .set(table.createBy).equalToWhenPresent(this::getCreateBy)
           .set(table.updateBy).equalToWhenPresent(this::getUpdateBy)
           .set(table.createTime).equalToWhenPresent(this::getCreateTime)
           .set(table.updateTime).equalToWhenPresent(this::getUpdateTime);
        dsl.where(table.id, SqlBuilder.isEqualTo(this::getId));
    }

    @Override
    @SuppressWarnings("all")
    public SqlColumn[] columns() {
        return new SqlColumn[]{table.id, table.name, table.code, table.structure, table.valueType, table.otherSetting, table.description, table.createBy, table.updateBy, table.createTime, table.updateTime};
    }

    @Override
    public Map<String, SqlColumn<?>> columnsMap() {
        Map<String, SqlColumn<?>> maps = new LinkedHashMap<>(11);
        maps.put("id", table.id);
        maps.put("name", table.name);
        maps.put("code", table.code);
        maps.put("structure", table.structure);
        maps.put("valueType", table.valueType);
        maps.put("otherSetting", table.otherSetting);
        maps.put("description", table.description);
        maps.put("createBy", table.createBy);
        maps.put("updateBy", table.updateBy);
        maps.put("createTime", table.createTime);
        maps.put("updateTime", table.updateTime);
        return maps;
    }

    @Override
    public SqlColumn<Long> id() {
        return table.id;
    }

    public static final class Table extends org.mybatis.dynamic.sql.AliasableSqlTable<Table> {
        public final SqlColumn<Long> id = column("ID_", JDBCType.BIGINT);

        public final SqlColumn<String> name = column("NAME_", JDBCType.VARCHAR);

        public final SqlColumn<String> code = column("CODE_", JDBCType.VARCHAR);

        public final SqlColumn<String> structure = column("STRUCTURE", JDBCType.VARCHAR);

        public final SqlColumn<String> valueType = column("VALUE_TYPE", JDBCType.VARCHAR);

        public final SqlColumn<String> otherSetting = column("OTHER_SETTING", JDBCType.VARCHAR);

        public final SqlColumn<String> description = column("DESCRIPTION", JDBCType.VARCHAR);

        public final SqlColumn<Long> createBy = column("create_by", JDBCType.BIGINT);

        public final SqlColumn<Long> updateBy = column("update_by", JDBCType.BIGINT);

        public final SqlColumn<LocalDateTime> createTime = column("create_time", JDBCType.TIMESTAMP);

        public final SqlColumn<LocalDateTime> updateTime = column("update_time", JDBCType.TIMESTAMP);

        public Table() {
            super("dic_define", Table::new);
        }
    }
}